< previous page page_314 next page >

Page 314
6. Set the Name of this menu item to mnuFileChild.
7. Add the following code to this menu item:
Private Sub mnuFileChild_Click()
Dim frm
New As frmChild

Set
frmNew = New frmChild

frmNew.Show
End Sub
analysis.gifIn many Windows applications, you have the ability to open many instances of the same form. For example, in Word, you can have many different documents open; in Excel, you can have many spreadsheets open. Each of these documents are not separate formstheyre created from a common template. This is what the preceding code accomplishes.
The New keyword in the line that assigns the form to the object variable frmNew is what informs Visual Basic to make a new instance of the form named frmChild. Think of this form as a photocopy of the original form. All the properties of the frmChild form are duplicated, and a new Form object variable is created. One important point to note is that the frmChild form is never loadedits only used to make a copy of itself for these new variables.
You can now use this menu item at runtime to see new instances of the form appear.

EXERCISE
Try Out the Window Menu Items
1. Run this project.
2. Click the New Child menu item three times.
3. You should now have three instances of the child form displayed.
4. Try out each of the menu items under the Window menu.
5. Minimize each of the forms and then move the icons on the parent MDI form to different locations. Now run the Arrange Icons menu item.
analysis.gifAs you can see keeping child forms in alignment is actually quite simple in Visual Basic.

 
< previous page page_314 next page >

If you like this book, buy it!